'''
逍 遥 派
# 逍遥：建议: 天性随意，男：washto 21 21 19 19，女：washto 21 21 20 18，
推荐天赋：str 21 int 21 con 18 dex 20
最终天赋：str 30 int 30 con 30 dex 29
性    格：狡黠多变
== 未完继续 79% == (q 离开，b 前一页，其他继续下一页)[K门派特点：翩若惊鸿影，婉若游龙身；凌波一微步，罗袜但生尘。
推荐武功：北冥神功 折梅手 凌波微步
先天注释：可兼容太玄、战神心经、百花错拳、庄子舞、玄冥掌、玄冥神功、易
          筋经、金蛇剑、五神剑、等几乎全部公共技能。
门派点评：逍遥同星宿一样，夕阳7中的可吸取十倍最大内力上限让这个大名在外
          却一直不冷不热的门派光鲜了起来。第一身法凌波微步在修得元神后
          形狸翻或庄子舞。北冥神功虽然取消了自动吸取内力，可内力系数在
          所有开放的内功中仅次于易筋经，十倍内力下内功类call die可说是
          第一神通，占尽优势，且还有自动防御特效。门派绝学化妖功在call
          die技能又是命中第一，唯一就是副本里有些吃力，却也可以依靠公共
          武功来达成，逍遥的粉丝一向不少，夕阳7里也终于可以达成心愿了...
'''
import functools, asyncio
from pymud import Alias, Trigger, SimpleCommand, SimpleTrigger, SimpleAlias
from pymud.settings import Settings

class Configuration:
    yzm = "cb3a8b56aaaec44c78aa1ddc7145bea2"
    name = "xyxfz"
    fname = "玄"
    lname = "疯紫"
    pwd = "a111111"
    suppwd = "880126"
    # m 男 f 女
    sex = "f"
    email = "shanghua_021@qq.com"
    choose = "2"
    washto = "21 21 20 18"
    born = "扬州人氏"

    hps=('rm','fy')

    def __init__(self, session) -> None:
        # 打开自动连接
        Settings.client["auto_reconnect"] = True
        self.session = session
    
        self._triggers = {}
        self._initTriggers()
        self.session.exec(self.name)

    def _initTriggers(self):
        self._triggers["tri_born0"] = SimpleTrigger(self.session,
            r"^注册验证串错误，请重新输入注册验证串.*",
            self.yzm,
            group="tri_born", id="tri_born0",
        )
        self._triggers["tri_born1"] = SimpleTrigger(self.session,
            r"^使用.+这个名字将会创造一个新的人物，您确定吗\(y\/n\)？$",
            'y',
            group="tri_born", id="tri_born1"
        )
        self._triggers["tri_born1_1"] = SimpleTrigger(self.session,
            r"^您的英文名字：|^好吧，那么请重新输入您的英文名字：|^请输入您的英文名字",
            self.name,
            group="tri_born", id="tri_born1_1"
        )
        self._triggers["tri_born2"] = SimpleTrigger(self.session,
            r"^您的中文姓氏\(不要超过两个汉字\)：",
            self.fname,
            group="tri_born", id="tri_born2"
        )
        self._triggers["tri_born3"] = SimpleTrigger(self.session,
            r"^您的中文名字\(不要超过两个汉字\)：",
            self.lname,
            group="tri_born", id="tri_born3"
        )
        self._triggers["tri_born4"] = SimpleTrigger(self.session,
            r"^请设定您的管理密码：|^请再输入一次您的管理密码，以确认您没记错：",
            self.suppwd,
            group="tri_born", id="tri_born4"
        )
        self._triggers["tri_born5"] = SimpleTrigger(self.session,
            r"^请输入你的普通密码：|^请再输入一次您的密码，以确认您没记错：",
            self.pwd,
            group="tri_born", id="tri_born5"
        )
        self._triggers["tri_born6"] = SimpleTrigger(self.session,
            r"^您要扮演男性\(m\)的角色或女性\(f\)的角色？",
            f'{self.sex};l',
            group="tri_born", id="tri_born6"
        )
        self._triggers["tri_born7"] = SimpleTrigger(self.session,
            r"^现在，请输入\s+register\s+您的email地址",
            f"register {self.email}",
            group="tri_born", id="tri_born7"
        )
        self._triggers["tri_born8"] = SimpleTrigger(self.session,
            r"^您可以选择\(choose\)的角色性格如下：",
            f"choose {self.choose}",
            group="tri_born", id="tri_born8"
        )
        self._triggers["tri_born9"] = SimpleTrigger(self.session,
            r"^你选择了.+的性格，接下来你可以洗\(washto\)天赋了。",
            f"washto {self.washto}",
            group="tri_born", id="tri_born9"
        )
        self._triggers["tri_born10"] = SimpleTrigger(self.session,
            r"^天赋总和为.+如果你满意，就去投胎\(born\)吧！",
            f"born {self.born};q",
            group="tri_born", id="tri_born10"
        )
        self._triggers["tri_born11"] = SimpleTrigger(self.session,
            r"^欢迎您来与我们共同历阅这个虚拟世界，特为您奉上一份小礼物以表心意！",
            "w;n;w;open door;nw;hp -g",
            group="tri_born", id="tri_born11"
        )
        # 【 容 貌 】  [ 30]    [ 30]    [  0]    [  0]    [  0]    [N/A]
        # 【 福 缘 】  [ 30]    [ 30]    [  0]    [  0]    [  0]    [N/A]
        self._triggers["tri_born12"] = Trigger(self.session,
            patterns=(
                r"^\s*【\s*容\s*貌\s*】\s+\[\s+(\d+)\]\s+",
                r"^\s*【\s*福\s*缘\s*】\s+\[\s+(\d+)\]\s+",
            ),
            group="tri_born", id="tri_born12",
            onSuccess = self.onTriggerGetHP
        )
        self._triggers["tri_born13"] = SimpleTrigger(self.session,
            r"^考虑清楚，确定的话请输入您的管理密码：",
            self.suppwd,
            group="tri_born", id="tri_born13"
        )
        self._triggers["tri_born13"] = Trigger(self.session,
            patterns=(
                r"^你的账号是新建的，本站规定新建账号必须连续在线半小时才能被有效保",
                r"^留，退出该游戏将删除你的账号，你确定要放弃该帐号而退出吗？（y\/n）",
            ),
            group="tri_born", id="tri_born13",
            onSuccess = self._onTriggerQuit
        )
        self.session.addTriggers(self._triggers)
    
    def _onTriggerQuit(self, name, line, wildcards):
        self.session.writeline('y')
    
    def onTriggerGetHP(self, name, line, wildcards):
        self.session.setVariables(self.hps, wildcards)
        self.session.create_task(self._asyncGetHP(wildcards))
    async def _asyncGetHP(self, wildcards):
        var = self.session.getVariables(self.hps)
        self.session.info(var[0])
        self.session.info(var[1])
        if int(var[0])!=30 or int(var[1])!=30:
            # self.session.writeline("suicide -f")
            self.session.writeline("quit")
        else:
            self.session.writeline("#unload")